package com.hy.controller;

import com.hy.appbase.apiresult.ApiDataResult;
import com.hy.appbase.apiresult.ApiResult;
import com.hy.appbase.page.PageResult;
import com.hy.bo.input.GazetteerAddBo;
import com.hy.bo.result.GazetteerRetBo;
import com.hy.bo.query.GazetteerQueryBo;
import com.hy.bo.result.GazetteerTreeRetBo;
import com.hy.model.Gazetteer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.hy.service.IGazetteerService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import java.util.List;

@Api("地域名录")
@RestController
@RequestMapping("/gazetteer")
public class GazetteerController {
	
	@Autowired
	IGazetteerService gazetteerService;

	@ApiOperation(value="getGazetteerById", notes="根据id查询地域信息")
	@ApiImplicitParam(name = "id", value = "地域ID", required = true, dataType = "String", paramType="path")
	@RequestMapping(value="/getGazetteerById/{id}", method = RequestMethod.GET)
	public ApiResult getGazetteerById(@PathVariable(value="id")String id) {
		GazetteerRetBo gazetteerRetBo = gazetteerService.getGazetteerById(id);
		return ApiDataResult.SUCCESS(gazetteerRetBo);
	}

	@ApiOperation(value ="saveGazetteer", notes = "保存地域信息")
	@ApiImplicitParam(name = "gazetteerAddBo", value = "地域信息", required = true, dataType = "GazetteerAddBo")
	@RequestMapping(value = "/saveGazetteer", method = RequestMethod.POST)
	public ApiResult saveGazetteer(@RequestBody GazetteerAddBo gazetteerAddBo) {
		GazetteerRetBo gazetteerRetBo = gazetteerService.saveGazetteer(gazetteerAddBo);
		return ApiDataResult.SUCCESS(gazetteerRetBo);
	}

	@ApiOperation(value = "deleteGazetteer", notes = "删除地域信息")
	@ApiImplicitParam(name="id", value = "地域ID",required = true, dataType = "String", paramType="path")
	@RequestMapping(value = "/deleteGazetteer/{id}", method = RequestMethod.DELETE)
	public ApiResult deleteGazetteer (@PathVariable(value = "id")String id) {
		gazetteerService.deleteGazetteer(id);
		return ApiResult.SUCCESS();
	}

	@ApiOperation(value ="pageGazetteer", notes = "分页查询")
	@ApiImplicitParam(name = "gazetteerQueryBo", value = "查询条件", required = true, dataType = "GazetteerQueryBo")
	@RequestMapping(value = "/pageGazetteer", method = RequestMethod.POST)
	public ApiResult pageGazetteer(@Validated @RequestBody GazetteerQueryBo gazetteerQueryBo) {
		PageResult<GazetteerRetBo> page = gazetteerService.page(gazetteerQueryBo);
		return ApiDataResult.SUCCESS(page);
	}

	@ApiOperation(value = "listGazetteer", notes = "条件查询")
	@ApiImplicitParam(name = "gazetteerQueryBo", value = "查询条件", required = true, dataType = "GazetteerQueryBo")
	@RequestMapping(value = "/listGazetteer", method = RequestMethod.POST)
	public ApiResult listGazetteer(@Validated @RequestBody GazetteerQueryBo gazetteerQueryBo) {
		List<Gazetteer> list = gazetteerService.list(gazetteerQueryBo);
		return ApiDataResult.SUCCESS(list);
	}

	@ApiOperation(value = "findAllGazetteerNode", notes = "条件查询")
	@RequestMapping(value = "/findAllGazetteerNode", method = RequestMethod.GET)
	public ApiResult findAllGazetteerNode() {
		GazetteerTreeRetBo gazetteerTreeRetBo = gazetteerService.findAllGazetteerNode();
		return ApiDataResult.SUCCESS(gazetteerTreeRetBo);
	}
}
